package com.example.hand.springboot_demo.api.controller.user;


import com.example.hand.springboot_demo.app.service.UserService;
import domain.entity.User;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/add-user/{age}")
    public Integer addUserApi(@PathVariable("age") Integer age){

        User user=new User();
        user.setUserName(Math.round(Math.random()*10)+"-"+"userName");
        user.setName(Math.round(Math.random()*10)+"-"+"name");
        user.setAge(age);


        return userService.addUser(user);
    }

    @RequestMapping("/update-user/{id}/{userName}/{name}/{age}")
    public Integer updateUserApi(@PathVariable("id") Long id,@PathVariable("userName") String userName, @PathVariable("name")String name, @PathVariable("age")Integer age){


        User user=new User();
        user.setId(id);
        user.setUserName(userName);
        user.setName(name);
        user.setAge(age);

        return userService.updateUser(user);
    }

    @RequestMapping("/delete-user/{id}")
    public Integer deleteUserApi(@PathVariable("id") Long id){

        return userService.deleteUser(id);
    }

    @RequestMapping("/select-user")
    public List<User> selectUserApi(){

        List<User> userList=userService.selectUser();



        return userList;
    }
}
